package com.example.demo.mapper;

import com.example.demo.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    /**
     * 查询博客列表
     */
    @Select("select id, title, content, user_id, delete_flag, create_time, update_time " +
            "from blog_info where delete_flag = 0")
    List<BlogInfo> selectBlogList();

    /**
     * 根据博客 id，返回博客信息
     */
    @Select("select id, title, content, user_id, delete_flag, create_time, update_time " +
            "from blog_info where id = #{id} and delete_flag = 0")
    BlogInfo selectById(Integer id);

    /**
     * 根据用户输入信息，更新博客
     */
    Integer updateBlog(BlogInfo blogInfo);

    /**
     * 根据博客 id, 删除博客
     */
    @Update("update blog_info set delete_flag = 1 where id = #{id} and delete_flag = 0")
    Integer deleteById(Integer id);

    /**
     * 根据用户输入信息，添加博客
     */
    @Insert("insert into blog_info (title, content, user_id) values (#{title}, #{content}, #{userId})")
    Integer insertBlog(BlogInfo blogInfo);
}
